#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 25;
const int M = 1e6 + 5;
const int K = 15;

int n, m, k, n1, m1;
struct Edge {
  int u, v, w;
  bool operator<(const Edge& o) const { return w < o.w; }
} e[M], t[N * K], d[N * K];
int f[N], d0[N];
void init(int n) { rep(i, 1, n) f[i] = i; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
bool merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return false;
  f[fy] = fx;
  return true;
}
ll kruskal_base() {
  init(n);
  sort(e + 1, e + m + 1);
  ll res = 0;
  int cnt = 0;
  rep(i, 1, m) if (merge(e[i].u, e[i].v)) {
    res += e[i].w;
    t[++cnt] = e[i];
    if (cnt == n - 1) break;
  }
  m = n - 1;
  rep(i, 1, m) e[i] = t[i];
  while (m1 && d[m1].w >= e[m].w) m1--;
  return res;
}
ll solve(int s) {
  bitset<10> bs(s);
  n1 = n;
  ll res = 0;
  rep(i, 1, k) {
    if (bs[i - 1]) res += d0[i], n1++;
  }
  init(n + k);
  int cnt = n1 - 1;

  for (int i = 1, j = 1; i <= m || j <= m1;) {
    Edge now;
    if (i <= m && j <= m1) {
      if (e[i].w <= d[j].w)
        now = e[i++];
      else
        now = d[j++];
    } else if (i <= m)
      now = e[i++];
    else
      now = d[j++];
    if (now.u > n && !bs[now.u - n - 1]) continue;
    if (merge(now.u, now.v)) {
      res += now.w;
      if (--cnt == 0) break;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  rep(i, 1, m) cin >> e[i].u >> e[i].v >> e[i].w;
  rep(i, 1, k) {
    cin >> d0[i];
    rep(j, 1, n) {
      int w;
      cin >> w;
      d[++m1] = {n + i, j, w};
    }
  }
  sort(d + 1, d + m1 + 1);
  ll ans = kruskal_base();
  rep(s, 1, (1 << k) - 1) ans = min(ans, solve(s));
  cout << ans;
  return 0;
}